#!/usr/bin/env python
import sys
import filechooser
import fileops
from Crypto.Cipher import *
import kripto

from PyQt4 import QtCore, QtGui, uic


class DemoImpl(QtGui.QDialog):

    def __init__(self, *args):
        QtGui.QWidget.__init__(self, *args)
        uic.loadUi("read.ui", self)

    @QtCore.pyqtSignature("")
    def on_filechooserbtn_clicked(self):
        try:
            path=filechooser.choose()
            resource=str(fileops.getResource(path))
            self.messagetextEdit.setPlainText(resource)
            key=str(self.keylineEdit.text())
            if len(key)>0 and len(self.messagetextEdit.toPlainText())>0:
                test = kripto.gizlilik(key,"~",Blowfish,Blowfish.MODE_ECB)
                self.messagetextEdit.setPlainText(test.coz(resource,key))
        except:
            print "select attachment file and dont forget write the key"
            
apps = QtGui.QApplication(sys.argv)
widgets =DemoImpl()
widgets.show()
apps.exec_()
